<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>
        <ui:composition template="./../Template/generalTemplate.xhtml">
            <ui:define name="content">
                <h:form id="form">
                    <p:panel id="func" header="Function Management" style="height:495px;">
                        <div style="margin-left:50px;margin-right:50px;margin-top:20px;">
                            <p:growl id="msgs" showDetail="true" /> 
                            <p:dataTable id="functionalities" value="#{manageFunctionalityManagedBean.getFunctionalities()}" var="funcList" scrollable="true" height="350">

                                <p:column headerText="Functionality Name" style="width:600px">
                                    <h:outputText value="#{funcList.funcName}"/>
                                </p:column>
                                <p:column headerText="Functionality ID" style="width:150px">
                                    <h:outputText value="#{funcList.funcId}"/>
                                </p:column>



                                <p:column style="width:100px;text-align:center;" headerText="Action">  

                                        <p:commandButton update=":form:display" oncomplete="carDialog.show()" image="ui-icon ui-icon-pencil" title="Edit">  
                                            <f:setPropertyActionListener value="#{funcList}" target="#{manageFunctionalityManagedBean.selectedFunctionality}" />  
                                            <f:setPropertyActionListener value="#{true}" target="#{manageFunctionalityManagedBean.editMode}" />  
                                        </p:commandButton>  
                                        <p:commandButton update=":form:display" oncomplete="confirmation.show()" image="ui-icon ui-icon-close" title="Delete" style="margin-left:10px;">  
                                            <f:setPropertyActionListener value="#{funcList}" target="#{manageFunctionalityManagedBean.selectedFunctionality}" />  
                                        </p:commandButton>  
                                </p:column>  

                            </p:dataTable>  

                            <p:dialog header="Edit Functionality" widgetVar="carDialog" resizable="false" id="carDlg"  
                                      showEffect="fade" hideEffect="explode" modal="true" width="500">  

                                <h:panelGrid id="display"  columns="2" cellpadding="4" style="margin:0 auto;">  



                                    <h:outputText value="Functionality Name" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{manageFunctionalityManagedBean.selectedFunctionality.funcName}" style="font-weight:bold" rendered="#{!manageFunctionalityManagedBean.editMode}"/>  
                                        <p:inputText id="funcName" required="true" requiredMessage="Functionality Name cannot be empty" value="#{manageFunctionalityManagedBean.selectedFunctionality.funcName}" rendered="#{manageFunctionalityManagedBean.editMode}"  label="Functionality Name"/>  
                                        <p:message for="funcName"/>
                                    </h:panelGroup>  

                                    <h:outputText value="Functionality ID" />  
                                    <h:panelGroup>  
                                        <h:outputText value="#{manageFunctionalityManagedBean.selectedFunctionality.funcId}" style="font-weight:bold" rendered="#{!manageFunctionalityManagedBean.editMode}"/>  
                                        <p:inputText id="funcID" required="true" requiredMessage="Functionality ID cannot be empty" value="#{manageFunctionalityManagedBean.selectedFunctionality.funcId}" rendered="#{manageFunctionalityManagedBean.editMode}"  label="Functionality ID"/>  
                                        <p:message for="funcID"/>
                                    </h:panelGroup>  


                                    <f:facet name="footer">  
                                        <p:outputPanel rendered="#{manageFunctionalityManagedBean.editMode}" layout="block" style="text-align:right">  
                                            <p:commandButton value="Save" update="functionalities msgs" actionListener="#{manageFunctionalityManagedBean.saveChanges}"   
                                                             oncomplete="carDialog.hide()" image="ui-icon ui-icon-check"/>  
                                            <p:commandButton value="Cancel" onclick="carDialog.hide()" type="button" image="ui-icon ui-icon-close"/>  

                                        </p:outputPanel>  
                                    </f:facet>  
                                </h:panelGrid>  

                            </p:dialog>

                            <p:confirmDialog message="Are you sure?" width="200"  
                                             showEffect="explode" hideEffect="explode"  
                                             header="Confirm" severity="alert" widgetVar="confirmation">  

                                <p:commandButton value="Yes" update="functionalities" actionListener="#{manageFunctionalityManagedBean.deleteFunctionality}" oncomplete="confirmation.hide()">  
                                    <f:attribute name="code1" value="#{manageFunctionalityManagedBean.selectedFunctionality.id}" />
                                </p:commandButton>
                                <p:commandButton value="Not yet" onclick="confirmation.hide()" type="button" />  

                            </p:confirmDialog>  
                        </div>
                    </p:panel>
                </h:form>  
            </ui:define>
        </ui:composition>
    </body>
</html>